<template>
  <div>
    <common-head title="选择收获地址" bg="#908" />
    <div class="main">
      <van-address-list
        v-model="chosenAddressId"
        :list="contacts"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select = "choseAddress"
      />
    </div>
  </div>
</template>

<script>
import CommonHead from '@components/CommonHead'
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
      chosenAddressId: '-1'
    }
  },
  created () {
    this.initChosenAddressId()
  },
  methods: {
    choseAddress (address) {
      this.setOrderContact(address)
      this.$router.go(-1)
    },
    initChosenAddressId () {
      this.chosenAddressId = this.currentOrder.contact.id
    },
    onAdd () {
      this.$router.push('/addContact')
    },
    onEdit (item, index) {
      this.$router.push(`/editContact/${index}`)
    },
    ...mapMutations(['setOrderContact'])
  },
  computed: {
    ...mapState(['contacts', 'currentOrder'])
  },
  components: {
    CommonHead
  }
}
</script>

<style lang="scss" scoped>
</style>
